﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HostpitalDevice.Business;

namespace HostpitalDevice
{
    public partial class ImportForm : Form
    {
        public string _source;
        public ImportForm(string source)
        {
            _source  = source;
            InitializeComponent();
        }

        public bool IsImportCompany()
        {
            return this.checkImportCompany.Checked ;
        }

        public bool IsImportSetting()
        {
            return this.checkImportSetting.Checked;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
             Business.DataImport di = new HostpitalDevice.Business.DataImport(_source );
             List<Object.Employee> list = di.GetAllEmployee();
             List<Object.TmpEmployee> tmplist = di.GetAllTmpEmployee();
             List<Company> comlist = di.GetAllCompany();
             List<Setting> setlist1 = di.GetAllSetting();

             Business.DataImport di2 = new HostpitalDevice.Business.DataImport();
             List<Setting> setlist2 = di2.GetAllSetting();
             if (this.IsImportSetting() == true)
             {
                 foreach (Setting set in setlist1)
                 {
                     di2.UpdateSettingBelow(set);
                 }
                 setlist2 = di2.GetAllSetting();
                 foreach (Setting set in setlist2)
                 {
                     di.UpdateSettingAbove(set);
                 }
             }
             if (this.IsImportCompany() == true)
             {
                 foreach (Company com in comlist)
                 {
                     di2.UpdateCompany(com);
                 }
             }
             foreach (Object.Employee ep in list)
             {
                 di2.UpdateEmployee(ep);
             }
             foreach (Object.TmpEmployee tep in tmplist)
             {
                 di2.UpdateEmployee(tep);
             }
             MessageBox.Show("上级数据同步成功");

            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
             MessageBox.Show("上级数据同步被中断");
            this.Close();
        }
    }
}